qui(function (require, exports, module) {
    Program.Util = $.extend(true, {}, EpgWeb.Util, {
        formatter: {
            qipuId: function (cellvalue, options, rowObject) {
                var plusUrl = EpgWeb.urlConfig.getQiPuBaseUrl(rowObject.qipuId);
                return "<a target='_blank' href='" + plusUrl + "'>" + rowObject.qipuId + "</a>";
            },
            pname: function (cellvalue, options, rowObject) {
                if (rowObject.pageUrl != null) {
                    return "<a target='_blank' href='" + rowObject.pageUrl + "'>" + cellvalue + "</a>";
                }
                return cellvalue;
            },
            playStatus: function (cellvalue, options, rowObject) {
                if (cellvalue == null) {
                    return "Not exist ";
                }
                switch (cellvalue) {
                    case -1:
                        return "未设定";
                    case 0:
                        return "未开始";
                    case 1:
                        return "直播中";
                    case 2:
                        return "回看中";
                    case 3:
                        return "回看结束";
                    default :
                        return "Not exist value:" + cellvalue;
                }
                return cellvalue;
            },
            bossStatus: function (cellvalue, options, rowObject) {
                var enumValue = "";
                switch (cellvalue) {
                    case "FREE":
                        enumValue = "免费";
                        break;
                    case "PAIED_NOT_AVAILABLE":
                        enumValue = "<span style='color: red'>付费未划价</span>";
                        break;
                    case "PAIED_AVAILABLE":
                        enumValue = "<span style='color: red'>付费已划价</span>";
                        break;
                    default:
                        break;
                }
                return enumValue;
            },
            type: function (cellvalue, options, rowObject) {
                var ret = "";
                var enumNameData = Program.Dao.liveProgramType();
                $.each(enumNameData.data, function (index, element) {
                    if (cellvalue == element.key) {
                        ret = element.descr;
                        return true;
                    }
                })
                return ret
            },
            episodeGrade: function (cellvalue, options, rowObject) {
                var ret = "";
                var enumNameData = Program.Dao.episodeGradeType();
                $.each(enumNameData.data, function (index, element) {
                    if (cellvalue == element.key) {
                        ret = element.descr;
                        return true;
                    }
                })
                if (ret == "A类一级") {
                    ret = "<span style='color: red'>" + ret + "</span>";
                }
                return ret;
            },
            log_type: function (cellvalue, options, rowObject) {
                var ret = "";
                var enumNameData = Program.Dao.logType();
                $.each(enumNameData.data, function (index, element) {
                    if (cellvalue == element.key) {
                        ret = element.descr;
                        return true;
                    }
                })
                return ret;
            },

            channelName: function (cellvalue, options, rowObject) {
                var url = "http://epg.lego.iqiyi.com/epg/channel.html?channelName=" + encodeURIComponent(cellvalue.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">"));
                return "<a target='_blank' href='" + url + "'>" + cellvalue + "</a>";
            },
            onlineStatus: function (cellvalue, options, rowObject) {
                if (cellvalue == 0) {
                    return "删除";
                } else if (cellvalue == 1) {
                    return "启用";
                }
            },
            formal: function (cellvalue, options, rowObject) {
                if (cellvalue == 0) {
                    return "测试";
                } else if (cellvalue == 1) {
                    return "正式";
                }
            },
            operate: function (cellvalue, options, rowObject) {
                var forceCheckStr = "";
                var htmlArr = [];
                htmlArr.push("<a href='javascript:;' onclick='Program.Util.jumpLibraryToEdit(" + rowObject.id + "," + rowObject.fatherId + ")'>编目</a>");
                if (Program.Config.AUTH_FORCE_CHECK && rowObject.channelLiveType == 2) {
                    htmlArr.push("<a href='javascript:;' onclick='Program.Util.checkProgram(" + rowObject.id + ")'>紧急检查</a>");
                }
                htmlArr.push(Program.Util.getBroadcastControl(rowObject));
                htmlArr.push("</br><a href='javascript:;' onclick='Program.Util.delProgram(" + rowObject.id + ")'>删除</a>");
                htmlArr.push("<a href='javascript:;' onclick='Program.Util.openHistory(" + rowObject.id + ")'>详细</a>");
                if (rowObject.directorEnable === 1) {
                    htmlArr.push("<a href='javascript:;' onclick='Program.Util.openDirector(" + rowObject.id + ")'>导播</a>")
                }
                return htmlArr.join("  ")
            },
            operate2: function (cellvalue, options, rowObject) {
                return "<a href='javascript:;' onclick='Program.Util.jumpListToEdit(" + rowObject.id + "," + rowObject.fatherId + ")'>编目</a>  " +
                    Program.Util.getBroadcastControl(rowObject) +
                    "<a href='javascript:;' onclick='Program.Util.delProgram(" + rowObject.id + ")'>删除</a>  " +
                    "<a href='javascript:;' onclick='Program.Util.openHistory(" + rowObject.id + ")'>详细</a>  ";
            },
            /**/
            publishStatus: function (checkValue) {
                if (checkValue == null)
                    return "";
                switch (checkValue) {
                    case 0:
                        return "未发布";
                    case 1:
                        return "已发布";
                    case 2:
                        return "页面下线";
                    case 3:
                        return "页面备用"
                    default:
                        return checkValue + "";
                }
            },
            purchase: function (checkValue) {
                if (checkValue == null)
                    return "";
                switch (checkValue) {
                    case 0:
                    case -100:
                        return "免费";
                    case 1:
                        return "收费";
                    default:
                        return checkValue + ""
                }

            },
            copyrightEndTime: function (checkValue) {
                if (checkValue == null) {
                    return "";
                }
                if (typeof( checkValue ) == "string") {
                    return checkValue;
                }
                if (checkValue <= 0) {
                    return "---";
                } else {
                    var date = new Date();
                    date.setTime(parseInt(checkValue));
                    return  EpgWeb.Util.formatDateTimeFormat(date);
                }
            },
            recommendRate: function (cellvalue, options, rowObject) {
                return Program.Config.RECOMMEND_RATE[cellvalue];
            },
            hot: function (cellvalue, options, rowObject) {
                if (rowObject.channelLiveType != 2) {
                    return "";
                }

                switch (cellvalue) {
                    case 0:
                        return "否";
                    case 1:
                        return "是";
                    default:
                        return "";
                }
            },
            test: function (cellvalue, options, rowObject) {
                if (rowObject.channelLiveType != 2) {
                    return "";
                }
                switch (cellvalue) {
                    case 0:
                        return "否";
                    case 1:
                        return "是";
                    default:
                        return "";
                }
            },
            publish_time: function (cellvalue, options, rowObject) {
                if (cellvalue != "") {
                    return EpgWeb.Util.formatDateTimeFormat(new Date(parseInt(cellvalue) * 1000));
                }
                return "";
            }
        },
        template: {
            daojuSuggest: function (itemArr) {
                return  '<div class="contract-item" >' +
                    '<span class="contract-width150" style="word-break:break-all">' + itemArr[0] + '</span>' +
                    '<span class="contract-width200" style="word-break:break-all">' + itemArr[1] + '</span>' +
                    '<span class="contract-width150" style="word-break:break-all">' + itemArr[2] + '</span>' +
                    '<span class="contract-width150" style="word-break:break-all">' + itemArr[3] + '</span>' +
                    '</div>'
            },
            voteSuggest: function (itemArr) {

                return '<div class="contract-item" >' +
                    '<span class="contract-width150" style="word-break:break-all">' + itemArr[0] + '</span>' +
                    '<span class="contract-width200" style="word-break:break-all">' + itemArr[1] + '</span>' +
                    '<span class="contract-width150" style="word-break:break-all">' + itemArr[2] + '</span>' +
                    '</div>';
            },
            albumSuggest: function (itemArr) {
                return   '<div class="contract-item" >' +
                    '<span class="contract-width100" style="word-break:break-all">' + itemArr[0] + '</span>' +
                    '<span class="contract-width150" style="word-break:break-all">' + itemArr[1] + '</span>' +
                    '<span class="contract-width60" style="word-break:break-all">' + itemArr[2] + '</span>' +
                    '<span class="contract-width120" style="word-break:break-all">' + itemArr[3] + '</span>' +
                    '<span class="contract-width80" style="word-break:break-all">' + itemArr[4] + '</span>' +
                    '<span class="contract-width80" style="word-break:break-all">' + itemArr[5] + '</span></div>'
            },
            puyuSuggest: function (itemArr) {
                var formatArr = [];
                formatArr.push('<span class="contract-width200" style="word-break:break-all">' + itemArr[0] + '</span>');
                formatArr.push('<span class="contract-width120" style="word-break:break-all">' + itemArr[1] + '</span>');
                formatArr.push('<span class="contract-width120" style="word-break:break-all">' + itemArr[2] + '</span>');
                formatArr.push('<span class="contract-width120" style="word-break:break-all">' + itemArr[3] + '</span>');
                formatArr.push('<span class="contract-width120" style="word-break:break-all">' + itemArr[4] + '</span>');
                formatArr.push('<span class="contract-width120" style="word-break:break-all">' + itemArr[5] + '</span>');
                formatArr.push('<span class="contract-width120" style="word-break:break-all">' + itemArr[6] + '</span>');
                formatArr.push('<span class="contract-width100" style="word-break:break-all">' + itemArr[7] + '</span>');
                formatArr.push('<span class="contract-width200" style="word-break:break-all">' + itemArr[8] + '</span>');
                return '<div class="contract-item" >' + formatArr.join("") + '</div>';
            },
            qitanSuggest: function (itemArr) {
                var formatArr = [];
                formatArr.push('<span class="contract-width80" style="word-break:break-all">' + itemArr[0] + '</span>');
                formatArr.push('<span class="contract-width250" style="word-break:break-all">' + itemArr[1] + '</span>');
                formatArr.push('<span class="contract-width80" style="word-break:break-all">' + itemArr[2] + '</span>');
                return '<div class="contract-item" >' + formatArr.join("") + '</div>';
            },
            actorSuggest: function (itemArr) {
                var formatArr = [];
                formatArr.push('<span class="contract-width100" style="word-break:break-all">' + itemArr[0] + '</span>');
                formatArr.push('<span class="contract-width150" style="word-break:break-all">' + itemArr[1] + '</span>');
                formatArr.push('<span class="contract-width150" style="word-break:break-all">' + itemArr[2] + '</span>');
                formatArr.push('<span class="contract-width50" style="word-break:break-all">' + itemArr[3] + '</span>');
                formatArr.push('<span class="contract-width150" style="word-break:break-all">' + itemArr[4] + '</span>');
                formatArr.push('<span class="contract-width150" style="word-break:break-all">' + itemArr[5] + '</span>');
                return '<div class="contract-item" >' + formatArr.join("") + '</div>';
            },
            playbackSuggest: function (itemArr) {
                return this.albumSuggest(itemArr);
            },
            templateSuggest: function (item) {
                return this.albumSuggest([
                    item["id"],
                    item["label"] ,
                    item["channelName"] ,
                    this.formatter.copyrightEndTime(item.copyrightEndTime),
                    this.formatter.purchase(item.isPurchase),
                    this.formatter.publishStatus(item.pagePublishStatus)
                ])
            }
        },
        setContainer: function ($container) {
            this.$container = $container;
        },
        // 绑定节目编辑事件
        bindEditEvent: function ($container) {

            this._editBindEvent($container);
            this._initEditData($container);

            this._liveTypeLinkage();
            this._initEditEvent();
        },

        _initEditEvent: function () {
            var self = this;
        },
        dispatchLiveChannelType: function (objKey, objValue) {
            return (  parseInt(objKey) < 5 && objValue == "1") ||
                (parseInt(objKey) > 5 && objValue == "2" ) ||
                (  parseInt(objKey) == 5 && objValue == "3" )
        },
        getBroadcastControl: function (rowObj) {
            var hasStream = null != rowObj.channelHasStream && rowObj.channelHasStream == 1;
            if (hasStream) {
                return "<a href='javascript:;' onclick='Program.Util.jumpToBroadcast(" + rowObj.id + "," + rowObj.fatherId + ")'>播控中心</a> ";
            } else {
                return "<a class='disabled'>播控中心</a> ";
            }
        },
        jumpLibraryToEdit: function (entityId, fatherId) {
            var openUrl = "program_edit.html?id=" + entityId + "&from=library&fatherId=" + fatherId;
            window.open(openUrl);
        },
        jumpListToEdit: function (entityId, fatherId) {
            var openUrl = "program_edit.html?id=" + entityId + "&from=list&fatherId=" + fatherId;
            window.open(openUrl);
        },
        jumpListToAdd: function (fatherId) {
            var openUrl = "program_edit.html?from=list&fatherId=" + fatherId;
            window.open(openUrl);
        },
        jumpToBroadcast: function (entityId, fatherId) {
            var openUrl = "broadcast_manager_episode.html?programId=" + entityId + "&id=" + fatherId;
            window.open(openUrl);
        },
        jumpToDirector: function (programQipuId) {
            var openUrl = (auth.dev() ? "" : "http://dbt.lego.iqiyi.com/epg/") + "program_director.html?programQipuId=" + programQipuId
            window.open(openUrl);
        },

        checkProgram: function (entityId) {
            Program.Dao.doAuthData({
                url: '/epg/auth/forceCheck',
                doError: function () {
                    EpgWeb.Plugin.showTips({content: '很抱歉，您没有权限!', type: "error"})
                },
                doSuccess: function () {
                    Program.Dao.forceCheckProgram({id: entityId }, function (data) {
                        if (data.code == "A00000") {
                            EpgWeb.Plugin.showTips({ content: data.msg})
                        } else {
                            EpgWeb.Plugin.showTips({ content: data.msg, type: "error"})
                        }
                    })
                }
            })
        },
        checkPlaying: function () {
            var self = this;
            var aimGrid = $("#list");
            var dataOriginl = aimGrid.jqGrid("getData");
            var current = self.formatDateTimeFormat(new Date());
            if (dataOriginl == null || dataOriginl.length == 0) {
                return;
            }
            $.each(dataOriginl, function (i, element) {
                if (element.startPlayTime <= current && current <= element.endPlayTime) {
                    console.log(" id:" + element.id);
                    aimGrid.setCell(element.id, "startPlayTime", '', {backgroundColor: "#3cb371"}, true);
                    aimGrid.setCell(element.id, "endPlayTime", '', {backgroundColor: "#3cb371"}, true)
                }
            });
        },
        delProgram: function (entityId, fatherId) {
            Program.Dao.doAuthData({
                url: '/epg/program_delete.html',
                doError: function () {
                    EpgWeb.Plugin.showTips({content: '很抱歉，您没有删除的权限!', type: "error"})
                },
                doSuccess: function () {
                    SystemDialog.queryConfirm("确认删除？", function (flag) {
                        if (flag === true) {
                            Program.Dao.deleteProgramData({id: entityId }, function (data) {
                                Program.Util.reloadHandler(data);
                            })
                        }
                    })
                }
            })
        },
        openDirector: function (entityId) {
            var dataArr = $("#list").getData();
            var selectEntity = null;
            $.each(dataArr, function (i, element) {
                if (element.id == entityId) {
                    selectEntity = element;
                    return false;
                }
            })
            if (selectEntity == null || selectEntity.directorEnable != 1) {
                return;
            }
            var forbidTime = new Date(selectEntity.endPlayTime.replace(/-/g, "/"))
            forbidTime.setDate(forbidTime.getDate() + 3);
            if (Date.now() > forbidTime.getTime()) {
                SystemDialog.queryAlert("导播台已经被回收!")
                return;
            }
            var newData = {
                programQipuId: selectEntity.qipuId,
                programName: selectEntity.pname,
                startPlayTime: selectEntity.startPlayTime,
                stopPlayTime: selectEntity.endPlayTime,
                source: 1,
                delay: 10,
                outputStreamType: "RESOLUTION_720P"
            };

            Program.Dao.doAuthData({
                url: '/epg/program_director.html',
                doError: function () {
                    EpgWeb.Plugin.showTips({content: '很抱歉，您没有导播的权限!', type: "error"})
                },
                doSuccess: function () {
                    Program.Dao.createDirector({"entity": JSON.stringify(newData)}, function (data) {
                        if (data == null) {
                            EpgWeb.Plugin.showTips({content: 'director/create 请求异常', type: "error"})
                        } else if (data.code != "A00000") {
                            if (data.data == "-1003") {
                                EpgWeb.Plugin.showTips({content: "第三方接口调用失败", type: "error"})
                            } else {
                                EpgWeb.Plugin.showTips({content: data.msg, type: "error"})
                            }
                        } else {
                            Program.Util.jumpToDirector(newData.programQipuId);
                        }
                    });
                }
            })
        },
        openHistory: function (entityId) {
            Program.Dao.doAuthData({
                url: '/epg/channel_log.html',
                doSuccess: function () {
                    Program.Config.AUTH_LOG_DETAIL = true;
                },
                doFinal: function () {
                    var tableConfig = $.extend(true, {}, Program.Config.TABLE_LOG);
                    tableConfig.width = Program.Config.AUTH_LOG_DETAIL ? 875 : 425
                    var colModel = tableConfig.colModel;
                    var newColModel = [];
                    var colModelConfig = Program.Config.TABLE_COLMODEL_CONFIG;

                    $.each(colModel, function (i, model) {
                        newColModel.push(colModelConfig[model]);
                    });
                    tableConfig.colModel = newColModel;
                    tableConfig.colModel[4].hidden = !Program.Config.AUTH_LOG_DETAIL;
                    $('#logList').jqGrid(tableConfig);
                    $("#programLogDiv").dialog({
                        title: "历史记录",
                        autoOpen: false,
                        width: Program.Config.AUTH_LOG_DETAIL ? 900 : 450,
                        height: 600,
                        modal: true,
                        dialogClass: 'alert',
                        open: function () {
                            $(".ui-dialog-titlebar-close").html('<span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span><span class="ui-button-text">close</span>');
                        }
                    });
                    $("#programLogDiv").dialog("open");
                    $('#logList').jqGrid('setGridParam', {
                        page: 1,
                        datatype: "json",
                        postData: {id: entityId}
                    }).trigger('reloadGrid');
                }
            })
        },
        getValidator: function ($container, config) {
            // var $container = this.$container;
            var $form = $container;
            var validator = Validator.getValidator($form, config);

            return validator;
        },
        //daoju  relation start

        createSign: function (obj, daoju_secret) {
            var self = this;
            var str = '';
            $.each(obj, function (k) {
                str += k + obj[k];
            });
            str += daoju_secret;
            console.log(str);
            return self.hex_sha1(self.utf16to8(str));
        },
        utf16to8: function (str) {
            var out, i, len, c;
            out = "";
            len = str.length;
            for (i = 0; i < len; i++) {
                c = str.charCodeAt(i);
                if ((c >= 0x0001) && (c <= 0x007F)) {
                    out += str.charAt(i);
                } else if (c > 0x07FF) {
                    out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
                    out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
                    out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
                } else {
                    out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
                    out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
                }
            }
            return out;
        },

        hex_sha1: function (str) {
            var hexcase = 0;
            var chrsz = 8;

            function dosha1(s) {
                return binb2hex(core_sha1(str2binb(s), s.length * chrsz));
            }

            function binb2hex(binarray) {
                var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
                var str = "";
                for (var i = 0; i < binarray.length * 4; i++) {
                    str += hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8 + 4)) & 0xF) + hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8)) & 0xF);
                }
                return str;
            }

            function core_sha1(x, len) {
                x[len >> 5] |= 0x80 << (24 - len % 32);
                x[((len + 64 >> 9) << 4) + 15] = len;

                var w = Array(80);
                var a = 1732584193;
                var b = -271733879;
                var c = -1732584194;
                var d = 271733878;
                var e = -1009589776;

                for (var i = 0; i < x.length; i += 16) {
                    var olda = a;
                    var oldb = b;
                    var oldc = c;
                    var oldd = d;
                    var olde = e;

                    for (var j = 0; j < 80; j++) {
                        if (j < 16) w[j] = x[i + j];
                        else w[j] = rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1);
                        var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)), safe_add(safe_add(e, w[j]), sha1_kt(j)));
                        e = d;
                        d = c;
                        c = rol(b, 30);
                        b = a;
                        a = t;
                    }

                    a = safe_add(a, olda);
                    b = safe_add(b, oldb);
                    c = safe_add(c, oldc);
                    d = safe_add(d, oldd);
                    e = safe_add(e, olde);
                }
                return Array(a, b, c, d, e);

            }

            function sha1_ft(t, b, c, d) {
                if (t < 20) return (b & c) | ((~b) & d);
                if (t < 40) return b ^ c ^ d;
                if (t < 60) return (b & c) | (b & d) | (c & d);
                return b ^ c ^ d;
            }

            function sha1_kt(t) {
                return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 : (t < 60) ? -1894007588 : -899497514;
            }

            function safe_add(x, y) {
                var lsw = (x & 0xFFFF) + (y & 0xFFFF);
                var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
                return (msw << 16) | (lsw & 0xFFFF);
            }

            function rol(num, cnt) {
                return (num << cnt) | (num >>> (32 - cnt));
            }

            function str2binb(str) {
                var bin = Array();
                var mask = (1 << chrsz) - 1;
                for (var i = 0; i < str.length * chrsz; i += chrsz)
                    bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i % 32);
                return bin;
            }

            return dosha1(str);
        },
        reloadHandler: function (data) {
            if (data != null) {
                EpgWeb.Plugin.showTips({content: data.msg, type: data.code == "A00000" ? "success" : "error"});
                if (data.code == "A00000") {
                    $("#list").trigger("reloadGrid")
                }
            } else {
                console.log("callbackHandler no return data");
            }
        },
        calculateDate: function (str) {//month 7days yestoday today
            var from_date = "", to_date = "";
            var d = new Date();
            var defaultEnd = this.formatDateTimeFormat(d);
            this.setZeroTime(d);
            if (str == "today") {
                from_date = this.formatDateTimeFormat(d);
                to_date = defaultEnd;
            }
            if (str == "yesterday") {
                d.setDate(d.getDate() - 1);
                from_date = this.formatDateTimeFormat(d);
                this.setDayLastTime(d);
                to_date = this.formatDateTimeFormat(d);
            }

            if (str == "7days") {
                d.setDate(d.getDate() - 6);
                from_date = this.formatDateTimeFormat(d);
                to_date = defaultEnd
            }
            if (str == "month") {
                d.setMonth(d.getMonth() - 1);
                from_date = this.formatDateTimeFormat(d);
                to_date = defaultEnd
            }
            if (str == "absToday") {
                from_date = this.formatDateTimeFormat(d);
                this.setDayLastTime(d);
                to_date = this.formatDateTimeFormat(d);
            }

            if (str == "absToday+") {
                this.setZeroTime(d);
                d.setHours(10);
                from_date = this.formatDateTimeFormat(d);
                d.setDate(d.getDate() + 1);
                to_date = this.formatDateTimeFormat(d);
            }

            this.bindDate("startDate", "endDate", { maxDate: to_date, maxDateTime: new Date(to_date.replace(/-/g, "/")), minDate: from_date, minDateTime: new Date(from_date.replace(/-/g, "/"))})
            $("input[name=startDate]").datetimepicker("setDate", new Date(from_date.replace(/-/g, "/")));
            $("input[name=endDate]").datetimepicker("setDate", new Date(to_date.replace(/-/g, "/")));
        },

        RemoteCheck: (function () {
            var timerId = -1;
            var _handler = null;
            var _startHandler = null;
            var _data = [];

            function startCheck() {
                _startHandler.call(this, _data);
                return setInterval(checkComplete, 16);
            }

            function checkComplete() {
                var allComplete = true;
                $.each(_data, function (index, element) {
                    if (!element.complete) {
                        allComplete = false
                        return true;
                    }
                })
                if (allComplete) {
                    clearInterval(timerId);
                    timerId = -1;
                    console.log("check data over");
                    _handler(_data);
                }
            }

            function doCheck(data, handler, startHandler) {
                if (timerId > 0) {
                    console.log("wait to remote check")
                    return;
                }
                _handler = handler;
                _startHandler = startHandler;
                if (data != null) {
                    if ($.isArray(data)) {
                        _data = data;
                    } else {
                        _data = [data];
                    }
                }
                if (_data == null || _data.length == 0) {
                    handler.call(null)
                    return;
                }

                if (timerId < 0) {
                    timerId = startCheck();
                }
            }

            function clear() {
                _data = [];
            }

            function addToCheck(checkData) {
                _data.push(checkData)
            }

            return{
                clear: clear,
                doCheck: doCheck,
                addToCheck: addToCheck
            }
        })()
    });


});